package com.loong.system.handler;

import com.loong.common.utils.TransformUtils;
import com.loong.system.business.SystemConfigKeyBusiness;
import com.loong.system.common.backend.param.SystemConfigKeyParam;
import com.loong.system.common.backend.param.SystemConfigKeyQueryParam;
import com.loong.system.common.backend.param.SystemPositionParam;
import com.loong.system.common.backend.result.SystemConfigKeyResult;
import com.loong.system.model.SystemConfigKey;
import com.loong.system.model.SystemPosition;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class SystemConfigKeyHandler {
    @Resource
    private SystemConfigKeyBusiness systemConfigKeyBusiness;

    /**
     * 保存key
     * @param param
     */
    public void save(SystemConfigKeyParam param){
        systemConfigKeyBusiness.save(TransformUtils.transform(param, SystemConfigKey.class));
    }

    /**
     * 更新key
     * @param param
     */
    public void update(SystemConfigKeyParam param){
        systemConfigKeyBusiness.updateByPrimaryKeySelective(TransformUtils.transform(param, SystemConfigKey.class));
    }

    /**
     * 根据位置id查询所有位置下的key
     * @param param
     * @return
     */
    public List<SystemConfigKeyResult> queryConfigKeyAll(SystemConfigKeyQueryParam param){
       return TransformUtils.transformList(systemConfigKeyBusiness.findAllBy("positionId",param.getPositionId()),SystemConfigKeyResult.class);
    }


    public void  delete(List<Long> id){
        systemConfigKeyBusiness.deleteByIds(StringUtils.join(id,","));
    }
}
